package com.ruoyi.question.service.impl;

import java.util.Date;
import java.util.List;

import com.ruoyi.common.utils.uuid.UUID;
import com.ruoyi.question.domain.QueListDetails;
import com.ruoyi.question.mapper.QueListDetailsMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.question.mapper.QueListMapper;
import com.ruoyi.question.domain.QueList;
import com.ruoyi.question.service.IQueListService;
import com.ruoyi.common.core.text.Convert;

/**
 * 清单管理Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-02-26
 */
@Service
public class QueListServiceImpl implements IQueListService 
{
    @Autowired
    private QueListMapper queListMapper;

    @Autowired
    private QueListDetailsMapper queListDetailsMapper;

    /**
     * 查询清单管理
     * 
     * @param id 清单管理主键
     * @return 清单管理
     */
    @Override
    public QueList selectQueListById(String id)
    {
        return queListMapper.selectQueListById(id);
    }

    /**
     * 查询清单管理列表
     * 
     * @param queList 清单管理
     * @return 清单管理
     */
    @Override
    public List<QueList> selectQueListList(QueList queList)
    {
        return queListMapper.selectQueListList(queList);
    }

    /**
     * 新增清单管理
     * 
     * @param queList 清单管理
     * @return 结果
     */
    @Override
    public int insertQueList(QueList queList)
    {
        String uuid = UUID.randomUUID().toString().replaceAll("-", "");
        queList.setId(uuid);

        Date date = new Date();
        queList.setCreatedAt(date);
        queList.setUpdatedAt(date);
        return queListMapper.insertQueList(queList);
    }

    /**
     * 修改清单管理
     * 
     * @param queList 清单管理
     * @return 结果
     */
    @Override
    public int updateQueList(QueList queList)
    {
        return queListMapper.updateQueList(queList);
    }

    /**
     * 批量删除清单管理
     * 
     * @param ids 需要删除的清单管理主键
     * @return 结果
     */
    @Override
    public int deleteQueListByIds(String ids)
    {
        return queListMapper.deleteQueListByIds(Convert.toStrArray(ids));
    }

    /**
     * 批量增加清单题目
     *
     * @param ids 需要增加的清单主键
     * @return 结果
     */
    @Override
    public int addQueListByIds(List<String> ids, String id)
    {
        List<QueListDetails> listDetails = queListDetailsMapper.selectQueListDetailsByListId(id);
        if (!listDetails.isEmpty()){
            queListDetailsMapper.deleteQueListDetailsByListId(id);
        }
        return queListMapper.addQueListByIds(ids, id);
    }

    /**
     * 删除清单管理信息
     * 
     * @param id 清单管理主键
     * @return 结果
     */
    @Override
    public int deleteQueListById(String id)
    {
        return queListMapper.deleteQueListById(id);
    }
}
